---
id: getting_started
title: Getting Started
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

This section shows you how to get your feet wet with BoTorch.

Before jumping the gun, we recommend you start with the high-level
[Overview](overview) to learn about the basic concepts in BoTorch.


## Installing BoTorch

#### Installation Requirements:

BoTorch is easily installed via `pip` (recommended). It is also possible to
use the (unofficial) [Anaconda](https://www.anaconda.com/distribution/#download-section)
package from the `-c conda-forge` channel.

<Tabs>
    <TabItem value="pip" label="pip" default>

```bash
pip install botorch
```

    </TabItem>
    <TabItem value="conda" label="Conda">

```bash
conda install botorch -c gpytorch -c conda-forge
```

    </TabItem>
</Tabs>

For more installation options and detailed instructions, please see the
[Project Readme](https://github.com/meta-pytorch/botorch/blob/main/README.md)
on GitHub.

## Basic Components

Here's a quick run down of the main components of a Bayesian Optimization loop.

1. Fit a Gaussian Process model to data
    ```python
    import torch
    from botorch.models import SingleTaskGP
    from botorch.models.transforms import Normalize
    from botorch.fit import fit_gpytorch_mll
    from gpytorch.mlls import ExactMarginalLogLikelihood

    train_X = torch.rand(10, 2, dtype=torch.double) * 2
    # explicit output dimension -- Y is 10 x 1
    train_Y = 1 - (train_X - 0.5).norm(dim=-1, keepdim=True)
    train_Y += 0.1 * torch.rand_like(train_Y)

    gp = SingleTaskGP(
        train_X=train_X,
        train_Y=train_Y,
        input_transform=Normalize(d=2),
    )
    mll = ExactMarginalLogLikelihood(gp.likelihood, gp)
    fit_gpytorch_mll(mll)
    ```

2. Construct an acquisition function
    ```python
    from botorch.acquisition import LogExpectedImprovement

    logNEI = LogExpectedImprovement(model=gp, best_f=train_Y.max())
    ```

3. Optimize the acquisition function
    ```python
    from botorch.optim import optimize_acqf

    bounds = torch.stack([torch.zeros(2), torch.ones(2)]).to(torch.double)
    candidate, acq_value = optimize_acqf(
        logNEI, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
    )
    ```


## Tutorials

Our Jupyter notebook tutorials help you get off the ground with BoTorch.
View and download them [here](tutorials/index.mdx).


## API Reference

For an in-depth reference of the various BoTorch internals, see our
[API Reference](https://botorch.readthedocs.io/).


## Contributing

You'd like to contribute to BoTorch? Great! Please see
[here](https://github.com/meta-pytorch/botorch/blob/main/CONTRIBUTING.md)
for how to help out.
